package com.globallogic.dailyplanner.utils;

import java.util.Date;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope("request")
public class ToDateValidator implements Validator{

	@Override
	public void validate(FacesContext context, UIComponent component, Object value)
			throws ValidatorException {
		Date from = (Date) component.getAttributes().get("from");
		Date to = (Date) value;

		DateUtil.endBeforeStart(to, from, "To date must after from date."); 
	}
}
